package com.springboot.erp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.erp.common.CommonResult;
import com.springboot.erp.entity.JshSupplier;
import com.springboot.erp.service.JshSupplierService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/JshSupplierService")
@RestController
@Slf4j
public class JshSupplierController {
@Resource
private JshSupplierService jshSupplierService;
    @GetMapping("/queryForPages")
    public Page<JshSupplier> queryForPages(@RequestParam(required = false) String supplier,
                                              @RequestParam(required = false) String phone,
                                              @RequestParam(required = false) String telephone,
                                              @RequestParam(required = false, defaultValue = "1") int current,
                                              @RequestParam(required = false, defaultValue = "10") int size,
                                              @RequestParam(required = false,defaultValue = "supplier_id") String orderBy,
                                              @RequestParam(required = false,defaultValue = "true") boolean asc){
        return jshSupplierService.selectForPagesSupI(supplier, phone, telephone, current, size, orderBy, asc);
    }
//    public Page<Address> queryForPages(@RequestParam(required = false) String address,
//                                       @RequestParam(required = false) String phone,
//                                       @RequestParam(required = false, defaultValue = "1") int current,
//                                       @RequestParam(required = false, defaultValue = "10") int size,
//                                       @RequestParam(required = false,defaultValue = "address_id") String orderBy,
//                                       @RequestParam(required = false,defaultValue = "true") boolean asc){
//        return addressService.selectForPages(address, phone, current, size, orderBy, asc);
@PostMapping("/addtOne")
    public CommonResult addtOne(@RequestBody JshSupplier jshSupplier){
        log.info("addOne");
    jshSupplierService.addOne(jshSupplier);
    return new CommonResult(0,"success", null);}


    @PutMapping("/updateOne")
    public CommonResult updateOne(@RequestBody JshSupplier jshSupplier){
        log.info("updateOne");
    jshSupplierService.updateOne(jshSupplier);
    return new CommonResult(0,"success", null);}

    @DeleteMapping("/deleteOne")
    public CommonResult deleteOne(@RequestParam Integer id){
        log.info("deleteOne");
    jshSupplierService.deleteOne(id);
    return new CommonResult(0,"删除成功", null); }
}
